package com.dingwei.lesyndrome.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.adapter.CoachTimetableAdapter;
import com.dingwei.lesyndrome.bean.CarTimeListBean;
import com.dingwei.lesyndrome.mvp.presenter.CoachTimetablePresenter;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.decoration.DividerDecoration;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.weight.TitleBar;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/2/28.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description : 长途汽车时刻表
 */

public class CoachTimetableActivity extends BaseActivity implements Contract.CoachTimetableView {
    CoachTimetablePresenter coachTimetablePresenter = new CoachTimetablePresenter(this);
    @Bind(R.id.title_bar)
    TitleBar titleBar;
    @Bind(R.id.m_recyclerView)
    RecyclerView mRecyclerView;
    @Bind(R.id.img_no_data)
    ImageView imgNoData;
    @Bind(R.id.tv_no_data)
    TextView tvNoData;
    @Bind(R.id.no_data_layout)
    RelativeLayout noDataLayout;
    CoachTimetableAdapter adapter;
    @Bind(R.id.data_layout)
    LinearLayout dataLayout;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_coach_timetable;
    }

    @Override
    protected void initData() {
        coachTimetablePresenter.initData();
    }

    @Override
    protected void initView() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);
        mRecyclerView.addItemDecoration(new DividerDecoration(getResources().getColor(R.color.line), 0));

        adapter = new CoachTimetableAdapter(BaseActivity.context);
        mRecyclerView.setAdapter(adapter);

        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                CarTimeListBean.DataBean.SdcountyListBean bean = adapter.getItem(position);
                intent = new Intent(BaseActivity.context,CoachDetailsActivity.class);
                intent.putExtra("id",bean.id);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void setData(CarTimeListBean bean) {
        adapter.addAll(bean.data.sdcountyList);
        showData("success");
    }

    @Override
    public void onFail() {
        showData("fail");
    }

    public void showData(String state) {
        if (state.equals("success")) {
            dataLayout.setVisibility(View.VISIBLE);
            noDataLayout.setVisibility(View.GONE);
        } else {
            dataLayout.setVisibility(View.GONE);
            noDataLayout.setVisibility(View.VISIBLE);
        }
    }
}
